/**************************************************************************(C)*
 *
 *  This file is part of the GreenHills project
 *  Copyright (C) 2009  Tieto Corporation
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  Not for commmercial use. Only with Tieto permission.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 *************************************************************************(C)*/
#include "addwaypointdialog.h"
#include "ui_addwaypointdialog.h"

using namespace greenhills::client;
using namespace greenhills::gps;

CAddWaypointDialog::CAddWaypointDialog(const QString &pName,
    const CGPSPosition &pPosition, QWidget *parent) :
    QDialog(parent),
    m_ui(new Ui::CAddWaypointDialog)
{
    m_ui->setupUi(this);

    m_ui->leName->setText(pName);
    m_ui->leLatitude->setText(pPosition.latitude().toString());
    m_ui->leLongitude->setText(pPosition.longitude().toString());
}

CAddWaypointDialog::~CAddWaypointDialog()
{
    delete m_ui;
}

void CAddWaypointDialog::changeEvent(QEvent *e)
{
    QDialog::changeEvent(e);
    switch (e->type()) {
    case QEvent::LanguageChange:
        m_ui->retranslateUi(this);
        break;
    default:
        break;
    }
}

CGPSPosition CAddWaypointDialog::position() const
{
    return CGPSPosition(
            CGPSLatitude::fromString(m_ui->leLatitude->text() +
                (m_ui->cbLatitude->currentIndex()==0 ? "N" : "S")),
            CGPSLongitude::fromString(m_ui->leLongitude->text()+
                (m_ui->cbLongitude->currentIndex()==0 ? "E" : "W")));
}

QString CAddWaypointDialog::name() const
{
    return m_ui->leName->text();
}
